package Map;

import java.util.HashMap;
import java.util.Set;
import java.util.Map;

public class HashMapDemo2 {
	public static void main(String[] args) {
		HashMap<Student,String> hm = new HashMap<>();
		
		Student s = new Student("张三",19);
		Student s1 = new Student("李四",20);
		Student s2 = new Student("王五",40);
		Student s4 = new Student("王五",40);
		
		hm.put(s, "ITCAST001");
		hm.put(s1, "ITCAST002");
		hm.put(s2, "ITCAST003"); 
		hm.put(s4, "ITCAST003"); 
		
		//遍历Map对象
		//方法1：获取所有的key
		Set<Student> keys = hm.keySet();
		for(Student key:keys) {
			String value = hm.get(key);
			System.out.println(value+key);
			
		}
		System.out.println("------");
		//方式2:使用EntrySet()获取Entry对象 
		Set<Map.Entry<Student,String>> entrys = hm.entrySet();
		for (Map.Entry<Student, String> entry : entrys) {
			Student s3 = entry.getKey();
			String value = entry.getValue();
			System.out.println(s3 +"="+value);
		}
	}
}
